<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Payment;

class PaymentController extends Controller
{
    //
    public function index(Request $request)
    {
    	$payment = Payment::get();
    	return view('admin.payment.index',['payment'=>$payment]);
    }

    public function create()
    {
    	return view('admin.payment.create');
    }

    public function store(Request $request)
    {
    	$this->validate($request,[
    			'name'=>'required',
    	],[
    			'name.required'=>'支付方式名称不能为空',
    	]);

    	$payment=new Payment;
    	$payment->name=$request->name;
    	// dd($payment);die;

    	if($payment->save()){
    		return redirect('/payment')->with('success','添加成功');
    	}else{
    		return back()->with('error','添加失败');
    	}
    }

    public function show($id)
    {

    }

    public function edit($id)
    {
    	$payment = Payment::findOrFail($id);

    	//显示模板
    	return view('admin.payment.edit',['payment'=>$payment]);
    }

    public function update(Request $request,$id)
    {
    	$payment = Payment::findOrFail($id);

    	$payment->name= $request->name;

    	if($payment->save()){
    		return redirect('/payment')->with('success','修改成功');

   		}else{
   			return back()->with('error','修改失败');
   		}
    }

    public function destroy($id)
    {
    	$payment = Payment::findOrFail($id);

    	if($payment->delete()){
    		return redirect('/payment')->with('success','执行成功');
    	}else{
    		return back()->with('error','执行失败');
    	}
    }



}
